list-[id].vue 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. <template>
  2. <!-- 页面头部 -->
  3. <HomePageHead></HomePageHead>
  4. <!-- 导航栏 -->
  5. <HomePageNavigation></HomePageNavigation>
  6. <!-- 列表页广告一 -->
  7. <HomeTopTen :imgurl="adImg1" v-if="adImg1"></HomeTopTen>
  8. <!-- 资讯列表 -->
  9. <div class="newsDetail">
  10. <div class="inner">
  11. <div class="innerLeft">
  12. <section class="book_son_right clearfix">
  13. <div class="book_son_right_ul clearfix">
  14. <div class="book_son_right_li clearfix" v-for="(item, index) in newsDetail" :key="index">
  15. <div class="book_son_right_li_img">
  16. <img class="book_son_right_li_img" :src="item.img_url" :title="item.title"
  17. v-if="item.img_url">
  18. </div>
  19. <div class="book_son_right_li_in clearfix">
  20. <h4 class="book_son_right_li_h4 dot1">{{ item.title }}</h4>
  21. <div class="book_son_right_li_dot3 dot3">
  22. {{ item.description }}
  23. </div>
  24. <NuxtLink :href="`/${item.pinyin}/${item.id}.html`" class="book_son_right_li_btn"
  25. :title="item.name">
  26. 查看详情
  27. </NuxtLink>
  28. </div>
  29. </div>
  30. </div>
  31. </section>
  32. <!-- 分页器 -->
  33. <div class="pagination" v-if="total > 0">
  34. <el-pagination size="small" background layout="prev, pager, next" :total="total" class="mt-4"
  35. :page-size="pageSize" prev-text="上一页" next-text="下一页" @change="changePage" />
  36. </div>
  37. </div>
  38. <div class="innerRight">
  39. <div class="rightMenuTitle">
  40. <NuxtLink :to="`/${parent_pinyin}/index.html`"> {{ parent_name }}</NuxtLink>
  41. </div>
  42. <ul>
  43. <li v-for="(item, index) in bottomMenu" :key="index">
  44. <NuxtLink :to="`/${item.pinyin}/list-1.html`" :title="item.name"
  45. v-if="item.category_id == pageId" class="active">
  46. {{ item.alias }}
  47. </NuxtLink>
  48. <NuxtLink :to="`/${item.pinyin}/list-1.html`" :title="item.name"
  49. v-else-if="item.category_id != pageId">
  50. {{ item.alias }}
  51. </NuxtLink>
  52. </li>
  53. </ul>
  54. </div>
  55. <div style="clear: both;"></div>
  56. </div>
  57. </div>
  58. <!-- 广告二 -->
  59. <HomeTopTen :imgurl="adImg2" v-if="adImg2"></HomeTopTen>
  60. <!-- 页面底部 -->
  61. <HomeFoot1></HomeFoot1>
  62. </template>
  63. <script setup>
  64. //1.页面依赖 start ---------------------------------------->
  65. import { ElPagination } from 'element-plus'
  66. import { ArrowRight } from '@element-plus/icons-vue'
  67. import { ref, onMounted } from 'vue';
  68. //获得跳转过来的id
  69. const route = useRoute();
  70. //获得当前的完整路径
  71. const fullPath = route.path;
  72. //拆分,取出来中间这一段,然后提取数字部分
  73. const segments = fullPath.split('/');
  74. const targetSegment = segments[2];
  75. const targetSegment1 = segments[1];
  76. //const numberPart = targetSegment.match(/\d+$/)?.[0];
  77. let articleId;
  78. let pageId;
  79. let routeId
  80. let activeId = parseInt(route.params.id);
  81. console.log('activeId', activeId);
  82. //通过导航路径反向查询导航id
  83. const getRouteId = await requestDataPromise('/web/getWebsiteRoute', {
  84. method: 'GET',
  85. query: {
  86. 'pinyin': targetSegment,
  87. },
  88. });
  89. if (getRouteId.code == 200) {
  90. articleId = getRouteId.data.id;
  91. pageId = getRouteId.data.category_id;
  92. } else {
  93. console.log("SSR waring ---------- SSR waring ---------- SSR waring ---------->")
  94. console.log("错误位置:通过url路径查询导航池id")
  95. console.log("后端错误反馈:", getRouteId.message)
  96. console.log("SSR waring ---------- SSR waring ---------- SSR waring ---------->")
  97. }
  98. //通过导航路径反向查询导航id
  99. const getRouteId1 = await requestDataPromise('/web/getWebsiteRoute', {
  100. method: 'GET',
  101. query: {
  102. 'pinyin': targetSegment1,
  103. },
  104. });
  105. if (getRouteId1.code == 200) {
  106. routeId = getRouteId1.data.category_id;
  107. } else {
  108. console.log("SSR waring ---------- SSR waring ---------- SSR waring ---------->")
  109. console.log("错误位置:通过url路径查询导航池id")
  110. console.log("后端错误反馈:", getRouteId1.message)
  111. console.log("SSR waring ---------- SSR waring ---------- SSR waring ---------->")
  112. }
  113. //面包屑导航
  114. const parent_name = ref("");
  115. const parent_id = ref("");
  116. const parent_pinyin = ref("");
  117. let getParentNav = async () => {
  118. const listData = await requestDataPromise('/web/getOneWebsiteCategory', {
  119. method: 'GET',
  120. query: {
  121. 'catid': routeId,
  122. },
  123. });
  124. if (listData.code == 200) {
  125. parent_name.value = listData.data.alias;
  126. parent_id.value = listData.data.parent_id;
  127. parent_pinyin.value = listData.data.aLIas_pinyin;
  128. } else {
  129. console.log("SSR waring ---------- SSR waring ---------- SSR waring ---------->")
  130. console.log("错误位置:获取面包屑导航")
  131. console.log("后端错误反馈:", listData.message)
  132. console.log("SSR waring ---------- SSR waring ---------- SSR waring ---------->")
  133. }
  134. }
  135. //获得父级栏目详情
  136. getParentNav();
  137. //1.页面依赖 end ---------------------------------------->
  138. //2.页面数据 start ---------------------------------------->
  139. //广告列表
  140. const adList = ref([]);
  141. let adImg1 = ref([]);
  142. let adImg2 = ref([]);
  143. async function getAdData() {
  144. const adData = await requestDataPromise('/web/getWebsiteAdvertisement', { method: 'GET', query: { 'ad_tag': 'PAGE' } });
  145. adList.value = adData.data;
  146. if (adData.code == 200) {
  147. for (let item of adData.data) {
  148. if (item.ad_tag == 'PAGE_0001') {
  149. adImg1.value = item;
  150. }
  151. if (item.ad_tag == 'PAGE_0002') {
  152. adImg2.value = item;
  153. }
  154. }
  155. } else {
  156. console.log("SSR waring ---------- SSR waring ---------- SSR waring ---------->")
  157. console.log("错误位置:获取详情页广告列表")
  158. console.log("后端错误反馈:", adData.message)
  159. console.log("SSR waring ---------- SSR waring ---------- SSR waring ---------->")
  160. }
  161. }
  162. getAdData();
  163. const newsDetail = ref({})
  164. const bottomMenu = ref([]);
  165. const total = ref(0);//总条数
  166. const page = ref(1);//当前页码
  167. const pageSize = ref(10); //每页显示的条数
  168. async function getPageMenu() {
  169. const mkdata = await requestDataPromise('/web/getWebsiteBookList', {
  170. method: 'GET',
  171. query: {
  172. 'id': pageId,
  173. 'page': page.value,
  174. 'pageSize': pageSize.value,
  175. },
  176. });
  177. bottomMenu.value = mkdata.data.category;
  178. newsDetail.value = mkdata.data.books;
  179. total.value = mkdata.data.count;
  180. }
  181. getPageMenu();
  182. //2.页面数据 end ---------------------------------------->
  183. //3.分页器 start ---------------------------------------->
  184. //分页事件
  185. let changePage = (value) => {
  186. console.log("当前页码", value);
  187. page.value = value;
  188. getPageMenu()
  189. }
  190. //3.分页器 end ---------------------------------------->
  191. //4.设置seo信息 start---------------------------------------->
  192. //4.1 设置seo信息
  193. const setData = await requestDataPromise('/web/getWebsiteFootInfo', {
  194. method: 'GET',
  195. query: {},
  196. });
  197. let seoTitle = setData.data.website_head.title;
  198. let seoDescription = setData.data.website_head.description;
  199. let seoKeywords = setData.data.website_head.keywords;
  200. let seoSuffix = setData.data.website_head.suffix;
  201. let seoName = setData.data.website_head.website_name;
  202. useSeoMeta({
  203. title: seoTitle + "_" + seoSuffix,
  204. meta: [
  205. { name: 'description', content: seoDescription + "_" + seoName + "_" + seoSuffix, tagPriority: 10 },
  206. { name: 'keywords', content: seoKeywords + "_" + seoName + "_" + seoSuffix, tagPriority: 10 }
  207. ]
  208. });
  209. //4.设置seo信息 end---------------------------------------->
  210. onMounted(async () => {
  211. //从客户端获取行政职能部门 加快打开速度
  212. const { $webUrl, $CwebUrl } = useNuxtApp();
  213. //广告1
  214. let url = `${$webUrl}/web/getWebsiteAdvertisement?ad_tag=snzxw_list_0001`
  215. const responseAd1 = await fetch(url, {
  216. headers: {
  217. 'Content-Type': 'application/json',
  218. 'Userurl': $CwebUrl,
  219. 'Origin': $CwebUrl
  220. }
  221. });
  222. const resultAd1 = await responseAd1.json();
  223. adImg1.value = resultAd1.data[0];
  224. //广告2
  225. let url2 = `${$webUrl}/web/getWebsiteAdvertisement?ad_tag=snzxw_list_0002`
  226. const responseAd2 = await fetch(url2, {
  227. headers: {
  228. 'Content-Type': 'application/json',
  229. 'Userurl': $CwebUrl,
  230. 'Origin': $CwebUrl
  231. }
  232. });
  233. const resultAd2 = await responseAd2.json();
  234. adImg2.value = resultAd2.data[0];
  235. })
  236. </script>
  237. <style lang="less" scoped>
  238. @import '@/assets/css/shukanList.less';
  239. </style>